Ext.define('PJ.view.celaquestionnairemanage.QuestionnaireManageEdit', {
    extend: 'AM.default.DefaultWindowForm',
    alias: ['widget.questionnaireManageEdit'],
    requires: ['AM.default.DateTime', 
               'AM.default.DefaultDateField',
               'AM.default.jsonp.DefaultSubmitJsonp'],
    
    modal: true,// 开启不允许点击其他组件
    frame: true,
    notEdit: true,
    width: 616,
    autoHeight: true,
    layout: 'form',
    
    initComponent: function(){
        var me = this;
        var bt = '<span style="color:red;">*</span>';
        /*
        var editHtml = "";
        if (this.notEdit) {
            editHtml = '<iframe id="descriptionQuestionnaire" src="htmlEdit.jsp?width=486&height=275&ieHeight=277" scrolling="no" frameborder="0" width="100%" height="315px"></iframe>';
        }
        */
        me.items = [{
            defaults: {
                labelAlign: 'right',
                labelWidth: 85,
                columnWidth: .5
            },
            border: false,
            xtype: "container",
            width: 576,
            layout: 'column',
            items: [{
                xtype: 'textfield',
                fieldLabel: bt + '问卷名称',
                name: 'questionnaireName',
                allowBlank: false, //显示红框是否必填,默认显示
                maxLength: 50,
                margin: '0 0 0 0',
                columnWidth: 1
            }, /*{
				xtype: 'defaultDate',
				fieldLabel: bt + '开始时间',
				name: 'beginDate',
				id: 'questionnaireSD',
				vtype: 'startLessEndDate',
				startLessEndDate: {
					targetCmpId: 'questionnaireED',
					isStart: true
				},
				margin: '5 0 0 0',
				emptyText: "请输入开始时间",
				allowBlank: false
			}, {
				xtype: 'defaultDate',
				fieldLabel: bt + '结束时间',
				name: 'endDate',
				id: 'questionnaireED',
				vtype: 'startLessEndDate',
				vtypeText: '结束时间不能早于开始时间！',
				startLessEndDate: {
					targetCmpId: 'questionnaireSD',
					isStart: false
				},
				margin: '5 0 0 0',
				emptyText: "请输入结束时间",
				allowBlank: false
			},*/ {
                xtype: 'textarea',
                fieldLabel:  '问卷说明',
                name: 'questionnaireExplain',
                allowBlank: true, //显示红框是否必填,默认显示
                margin: '6 0 0 0',
                columnWidth: 1,
                height: 275
            }/*, {
	            xtype: 'container',
	            border: true,
	            layout: 'column',
	    		anchor: "100%",
		        hidden: false,
		        columnWidth: 1,
			    padding: '4 2 0 0',
			    items: [{
			        xtype: 'label',
			        html: "问卷说明:",
					padding: '0 2 0 34'
			    }, {
			        xtype: 'container',
			        columnWidth: 1,
			        itemId: 'descriptionQuestionnaire',
			        html: editHtml
			    }]
	        }*/, {
            	xtype: 'hidden',
            	name: 'questionnaireId'
            }]
        }];
        this.buttons = [{
            text: '确定',
            scope: this,
            handler: function(button, event){
                var win = button.up('window');
                win.sub();
            }
        }, {
            text: '关闭',
            scope: this,
            handler: this.close
        }];
        this.callParent(arguments);
    },
    sub: function(){
        var win = this;
        var form = win.down('form');
        var baseForm = form.getForm();
        if (!baseForm.isValid()) {
            return;
        }
        var questionnaireId = baseForm.findField("questionnaireId").getValue();
        var url = "";
        if(questionnaireId == null || questionnaireId == ""){
        	url = win.grid.store.addUrl;
        }else {
        	url = win.grid.store.updateUrl;
        }
      //将输入的值返回给编辑器并将数据一并提交到后端保存
        //var descriptionQuestionnaire = document.getElementById("descriptionQuestionnaire").contentWindow;
        //var val = descriptionQuestionnaire.getValue();
        //baseForm.findField("questionnaireExplain").setValue(val); 
        if(gj_onlineLearning_constant.loadType == "jsonp"){
        	form.getForm().doAction('submitJsonp',{
        		url: url,
        		params: {},
        		success: function(f, action){
        			if (action.result.success) {
        				Ext.Msg.alert('消息', '操作成功！', function(){
        					var gridPanel = win.grid;
        					var store = gridPanel.getStore();
        					store.load();
        					win.close();
        				});
        			}
        		},
        		failure: function(f, action){
        			if (action.result) {
        				Ext.Msg.alert('错误', action.result.msg, function(){
        					win.saveToken();
        				});
        			}else {
        				Ext.Msg.alert('错误', "系统错误,请联系管理员!", function(){
        					win.saveToken();
        				});
        			}
        		}
        	});
        }else if(gj_onlineLearning_constant.loadType == "ajax"){
        	win.submit({
        		url: url,
        		params: {},
        		success: function(f, action){
        			if (action.result.success) {
        				Ext.Msg.alert('消息', '操作成功！', function(){
        					var gridPanel = win.grid;
        					var store = gridPanel.getStore();
        					store.load();
        					win.close();
        				});
        			}
        		},
        		failure: function(f, action){
        			if (action.result) {
        				Ext.Msg.alert('错误', action.result.msg, function(){
        					win.saveToken();
        				});
        			}
        			else {
        				Ext.Msg.alert('错误', "系统错误,请联系管理员!", function(){
        					win.saveToken();
        				});
        			}
        		}
        	});
        }
    }
    /*
 	//向编辑器中赋值显示数据及样式
    setEditValue: function(){
        var win = this;
        var descriptionQuestionnaire = win.down("#descriptionQuestionnaire");
        descriptionQuestionnaire.update('<iframe id="descriptionQuestionnaire" name="descriptionQuestionnaire" src="htmlEdit.jsp?editValue=questionnaireExplain&width=486&height=275&ieHeight=277" scrolling="no" frameborder="0" width="100%" height="315px"></iframe>');
    }
    */
});
